Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm: disable non-js exts outside package scopes #30501

Closed
wants to merge 2 commits into from
Closed

Conversation

guybedford
Copy link
Contributor

@guybedford guybedford commented Nov 15, 2019

Up until now the ES module resolver still supports loading .json and .node files outside of ES module scopes (with "type": "module"), mainly for backwards compatibility with the CJS resolver.

This PR locks down that behaviour to ensure we are shipping the stricter semantics that don't permit users to just import JSON modules directly. The goal here is that if something like the module types proposal takes off, then we haven't already locked in ecosystem semantics that assume JSON imports.

The reason this is important is because right now the unflagged implementation will allow an .mjs file to import JSON, which once people start using will tend to make this a difficult thing to remove.

If we get compatibility bugs, we can certainly relax this stance though, but our general approach to the implementation up until now has been to try to be conservative with the semantics to avoid wrong paths, which has so far served us well.

For the main entry into Node.js we have an explicit isMain check which will always support non-extensions for bin use cases and these types of files.

The change is actually just the simple change at https://github.com/nodejs/node/pull/30501/files#diff-8e67f407bc32a0569e25d7ecaff6e494L1308, the rest is mostly just taking a chance to refactor the resolver logic a bit while retaining the same semantics.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

test/es-module/test-esm-non-js.js Show resolved Hide resolved
@guybedford
Copy link
Contributor Author

//cc @nodejs/modules-active-members

@guybedford
Copy link
Contributor Author

I'd like to suggest fast-tracking this if there are no objections.

@guybedford guybedford added the fast-track PRs that do not need to wait for 48 hours to land. label Nov 15, 2019
@jkrems
Copy link
Contributor

jkrems commented Nov 15, 2019

(Adding my 👍 to the comment above assuming it's a fast-track vote comment.)

Copy link
Contributor

@MylesBorins MylesBorins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like a few more approvals before we land.

Lgtm

@MylesBorins
Copy link
Contributor

/cc @nodejs/modules-active-members

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Nov 16, 2019

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

MylesBorins pushed a commit that referenced this pull request Nov 17, 2019
PR-URL: #30501
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
@MylesBorins
Copy link
Contributor

landed in 250a995

MylesBorins pushed a commit that referenced this pull request Nov 17, 2019
PR-URL: #30501
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
@ljharb ljharb deleted the non-js-exts branch November 18, 2019 23:29
@BridgeAR BridgeAR mentioned this pull request Nov 19, 2019
MylesBorins pushed a commit that referenced this pull request Jan 12, 2020
PR-URL: #30501
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
PR-URL: #30501
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fast-track PRs that do not need to wait for 48 hours to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants